const express = require('express');
const commentRouter = express.Router();
const commentSding = require("../../services/commentSending");

// 评论信息
commentRouter.get('/commentPost', async(req, res) => {
        let { commodityId } = req.query;
        console.log(commodityId);
        if (commodityId == "") return res.send({
            meta: { msg: "未传参数", status: 422 }
        })
        let result = await commentSding.CommodityReview(commodityId);
        res.send({
            data: {
                result
            },
            meta: {
                msg: "数据获取成功",
                status: 200
            }
        })
    })
    // 发表评论
commentRouter.post("/Published", async(req, res) => {
    let { commodityId, username } = req.body;
    // console.log(username);
    // console.log(commodityId);
    if (commodityId == "" || username == "") return res.send({
        data: {},
        meta: { msg: "未传参数！", status: 422 }
    })
    let result = await commentSding.commentPublished(req.body);
    if (result) {
        return res.send({
            data: {
                result
            },
            meta: {
                msg: "发表成功",
                status: 200
            }
        })
    } else {
        return res.send({
            meta: {
                msg: "发送失败",
                status: 404
            }
        })
    }

})


module.exports = commentRouter;